package Iterator_Pattern.Student;

import java.util.*;

// -*-coding:utf-8 -*-
//人员：刘陆鑫
//班级：19软3
//学号；2019110218
class Student implements Comparable<Student>{
    private String name;
    private int age;
    public Student(String name,int age){
        super();
        this.name=name;
        this.age=age;
    }
    public int compareTo(Student e){
        if(this.age>e.age){
            return -1;
        }else if(this.age<e.age){
            return 1;
        }else {
            return 0;
        }

    }
    public String toString(){
        return "姓名"+this.name+"年龄"+this.age;
    }
}
public class Client {
    public static void main(String[] args) {
        Student s1 = new Student( "张", 50);
        Student s2 = new Student( "李", 30);
        Student s3 = new Student( "王", 29);
        Student s4 = new Student( "高", 34);
        List<Student> list=new ArrayList<Student>();
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        Collections.sort(list);
        System.out.println("按年龄输出");
        for(Student student:list){
            System.out.println(student.toString());
        }
    }
}

